# -*- coding: utf-8 -*-


from HuobiDMService import HuobiDM
# import datetime
import time

URL = 'https://api.btcgateway.pro'
ACCESS_KEY = ''
SECRET_KEY = ''

dm = HuobiDM(URL, ACCESS_KEY, SECRET_KEY)

def xx(p1,p2):
    # p1='BTC_CQ'
    # p2='BTC_NQ'
#        symbol = p1[:3]
#        dit ={'CW':'this_week','NW':'next_week','CQ':'quarter','NQ':'next_quarter'}
    try:
        a = dm.get_contract_depth(p1, 'step6')
        b = dm.get_contract_depth(p2, 'step6')
        a1 = b.get('tick').get('asks')[0][0]
        a2 = a.get('tick').get('bids')[0][0]
        a3 = b.get('tick').get('bids')[0][0]
        a4 = a.get('tick').get('asks')[0][0]
    except Exception as e:
        print(f'error is {e}')
        time.sleep(2)
#            continue
    diff = '%.4f'%((a1-a2)/a2)
    dif = '%.4f'%((a3-a4)/a4)
    
    print(f'{p1[:3]} 开仓价差，{dif}')
    print(f'{p1[:3]} 平仓--价差，{diff}')

while True:
    
    s_list = [['BTC_CQ','BTC_NQ'],['ETH_CQ','ETH_NQ'],['DOT_CQ','DOT_NQ']]
    for i in s_list:
        xx(i[0],i[1])
    print('---------------------')
    time.sleep(30)


 




